home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…tember: Reference Library / Dev.CD Sep 98 RL2.toast / What's New / Software Development Kits / MacOS USB DDK / Examples / MouseModule / MouseConfigParse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-20  |  2.0 KB  |  59 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ConfigParse.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. #include <Types.h>
  12. #include <Devices.h>
  13. #include <processes.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "MouseModule.h"
  19.  
  20. OSErr FindHIDInterfaceByNumber(LogicalAddress pConfigDesc, UInt32 ReqInterface, USBInterfaceDescriptorPtr * hInterfaceDesc)
  21. {
  22. UInt32 totalLength;
  23. void * pEndOfDescriptors;
  24. USBInterfaceDescriptorPtr     pMyIntDesc;
  25. USBDescriptorHeaderPtr        pCurrentDesc;
  26. unsigned long                anAddress, anOffset;
  27.  
  28.     totalLength = USBToHostWord(((USBConfigurationDescriptorPtr)pConfigDesc)->totalLength);
  29.     pEndOfDescriptors = (Ptr)pConfigDesc + totalLength;                    // get the total length and add it to the start of the config space
  30.     pCurrentDesc = (USBDescriptorHeaderPtr)pConfigDesc;                    // point the currentdesc to the start of the config space
  31.     
  32.     while (pCurrentDesc < pEndOfDescriptors)                            // as long as we haven't exhausted all the descriptors
  33.     {
  34.         if (pCurrentDesc->descriptorType == kUSBInterfaceDesc)            // look at the current descriptor
  35.         {
  36.             pMyIntDesc = (USBInterfaceDescriptorPtr)pCurrentDesc;        // if it's an interface descriptor
  37.             if ((pMyIntDesc->interfaceClass == kUSBHIDInterfaceClass) &&
  38.                 (pMyIntDesc->interfaceNumber == ReqInterface))            // and if it's the interface we want...
  39.             {
  40.                 *hInterfaceDesc = pMyIntDesc;                            // if it is, then return with hInterfaceDesc set to the
  41.                 return noErr;                                            // current descriptor pointer
  42.             }
  43.         }
  44.         // (Ptr)pCurrentDesc += pCurrentDesc->length;                    // Nope, that either wasn't an interface descriptor
  45.         anAddress = (unsigned long) pCurrentDesc;                        // Nope, that either wasn't an interface descriptor
  46.         anOffset  = (unsigned long) pCurrentDesc->length;
  47.         anAddress += anOffset;
  48.         pCurrentDesc = (USBDescriptorHeaderPtr) anAddress;
  49.         if (pCurrentDesc->length == 0)
  50.             break;
  51.     }                                                                    // or it was, but not the droid we're looking for.
  52.     *hInterfaceDesc = NULL;
  53.     return kUSBInternalErr;
  54. }
  55.  
  56.  
  57.  
  58.  
  59.